package com.kerwin.async;


import com.kerwin.utils.SpringContextUtil;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/*这里是消费者*/
/*消费线程执行任务的*/
public class AsyncManager {
    /*这里接收Runnable 对象*/
public static void execute(Runnable runnable){
    /*为什么是这个呢  ThreadPoolTaskExecutor*/
    /*你看这个就是注入了配置信息的*/
    /*执行线程对象*/
/** public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport implements AsyncListenableTaskExecutor, SchedulingTaskExecutor {
    private final Object poolSizeMonitor = new Object();
    private int corePoolSize = 1;
    private int maxPoolSize = Integer.MAX_VALUE;
    private int keepAliveSeconds = 60;
    private int queueCapacity = Integer.MAX_VALUE;
    private boolean allowCoreThreadTimeOut = false;*/

    /*spring自动帮我们把 执行对象注入容器里面了*/
    /* @ConditionalOnMissingBean({Executor.class})
    public ThreadPoolTaskExecutor applicationTaskExecutor(TaskExecutorBuilder builder) {
        return builder.build();
    }*/
    /*所以直接从容器里面拿就好了，不要自己new*/
    /*自己new 还需要指配置信息的*/


    ThreadPoolTaskExecutor bean = SpringContextUtil.getBean(ThreadPoolTaskExecutor.class);
    bean.execute(runnable);

}

}
